﻿
IF EXISTS (SELECT 1 FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sproc_CF_GetFilesByCatalog_V2]') AND type in (N'P', N'PC'))
    DROP PROCEDURE [dbo].[sproc_CF_GetFilesByCatalog_V2];
GO

CREATE PROCEDURE [dbo].[sproc_CF_GetFilesByCatalog_V2]
    @CatalogID int 
AS
BEGIN
SET NOCOUNT ON;

IF ( @CatalogID = -1 )
BEGIN
    -- get all files
    SELECT
        F.*,
        G.Catalog
    FROM dbo.UDS_CF_File F INNER JOIN dbo.UDS_CF_Catalog G ON F.CatalogID = G.CatalogID;
END
ELSE
BEGIN
    SELECT
        F.*,
        G.Catalog
    FROM dbo.UDS_CF_File F INNER JOIN dbo.UDS_CF_Catalog G ON F.CatalogID = G.CatalogID
    WHERE F.CatalogID = @CatalogID;
END

END
GO
